'use strict'
var f2Controller = require('./f2.controller')
var f2View = require('./f2.view.html')
exports = module.exports = function ($scope, $rootScope, $timeout, $stateParams, $uibModal, yxtable14, $compile, $alert, $API, $go, $rule) {

    $scope.Rule = $rule
    var json = {
        api: {
            title: '任礼游系统 用户',
            url: '/api/renliyou/user'
        },
        requestColume: [
            {title:'reg',note:'运营人员ID',type:'文本',isInOut:"in",required:true,sub:[]},
            {title:'id',note:'主账号id,传0时此账户为主账号',type:'文本',isInOut:"in",required:true,sub:[]},
            {title:'account',note:'账号',type:'文本',isInOut:"in",sub:[]},
            {title:'pwd',note:'密码',type:'文本',isInOut:"in",sub:[]},
            {title:'province',note:'省',type:'文本',isInOut:"in",sub:[]},
            {title:'city',note:'市',type:'文本',isInOut:"in",sub:[]},
            {title:'area',note:'区',type:'文本',isInOut:"in",sub:[]},
            {title:'payname',note:'收款人',type:'文本',isInOut:"in",sub:[]},
            {title:'headBank',note:'收款银行',type:'文本',isInOut:"in"},
            {title:'bankName',note:'开户行,分行支行信息',type:'文本',isInOut:"in",sub:[]},
            {title:'bankNum',note:'收款账号',type:'文本',isInOut:"in",sub:[]},
            {title:'idCard',note:'身份证号',type:'文本',isInOut:"in",sub:[]},
            {title:'realName',note:'联系人',type:'文本',isInOut:"in",sub:[]},
            {title:'mobile',note:'手机',type:'文本',isInOut:"in",sub:[]},
            {title:'code',note:'手机验证码',type:'文本',isInOut:"in",sub:[]},
            {title:'qq',note:'QQ',type:'文本',isInOut:"in",sub:[]},
            {title:'wechat',note:'微信',type:'文本',isInOut:"in",sub:[]}
        ]
    }
    $scope.fromObj = json
    $scope.addItem = function(objName) {
        $scope.fromObj[objName].push({title:'',note:'',type:'',isInOut:"",required:false,sub:[]})
    }
    $scope.removeItem = function(objName, index) {
        $scope.fromObj[objName].splice(index, 1)
    }
    $scope.addSubItem = function(arr) {
        arr.push({})
    }
    $scope.removeSubItem = function(arr, index) {
        arr.splice(index, 1)
    }
    var templateA = ''; // 表单假数据预生产变量
    $scope.makeApiCode = (function() {
        templateA = ''
        templateA += `
                                                                                                        var API = {
                                                                                                            'title': '${ json.api.title } (表单提交) '
                                                                                                            'url':'${ json.api.url }Edit', 
                                                                                                            'method': 'POST',
                                                                                                            'request': {
                                                                                                                'header': {},
                                                                                                                'params': {`
        for(var i = 0, l = json.requestColume.length; i < l; i++){
            var one = json.requestColume[i]
            if( one.type == '文本' ){
                templateA += `
                                                                                                                    '${ one.title }': '', \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数字' ){
                templateA += `
                                                                                                                    '${ one.title }': 1, \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数组' ){
                templateA += `
                                                                                                                    '${ one.title }': ['aaa', 'bbb', 'ccc'], \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '对象' ){
                templateA += `
                                                                                                                    '${ one.title }': { \/\/${ one.required?'(必填) ':'' }${ one.note }；`
                for(var ii = 0, li = one.sub.length; ii < li; ii++){
                    var two = one.sub[ii]
                    templateA += `
                                                                                                                        '${ two.title }': '', \/\/${ two.note }；`

                }
                templateA += `
                                                                                                                    },`
            } else if( one.type == '对象数组' ){
                templateA += `
                                                                                                                    '${ one.title }': [ { \/\/${ one.required?'(必填) ':'' }${ one.note }；`
                for(var ii = 0, li = one.sub.length; ii < li; ii++){
                    var two = one.sub[ii]
                    templateA += `
                                                                                                                        '${ two.title }': '', \/\/${ two.note }；`

                }
                templateA += `
                                                                                                                    } , ...],`
            }
        }
        templateA += `
                                                                                                                }
                                                                                                            },
                                                                                                            'response': {
                                                                                                                'code': '200',
                                                                                                                'msg': '',
                                                                                                                'data': {
                                                                                                                    'resCode':1, // 处理结果::0失败1成功
                                                                                                                    'res':'' // 返回提示信息
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                        var API = {
                                                                                                            'title': '${ json.api.title } (读取详情) '
                                                                                                            'url':'${ json.api.url }Detail', 
                                                                                                            'method': 'GET',
                                                                                                            'request': {
                                                                                                                'header': {},
                                                                                                                'params': {
                                                                                                                    'id': 1, \/\/ ID
                                                                                                                }
                                                                                                            },
                                                                                                            'response': {
                                                                                                                'code': '200',
                                                                                                                'msg': '',
                                                                                                                'data': {`
        for(var i = 0, l = json.requestColume.length; i < l; i++){
            var one = json.requestColume[i]
            if( one.type == '文本' ){
                templateA += `
                                                                                                                    '${ one.title }': '', \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数字' ){
                templateA += `
                                                                                                                    '${ one.title }': 1, \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数组' ){
                templateA += `
                                                                                                                    '${ one.title }': ['aaa', 'bbb', 'ccc'], \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '对象' ){
                templateA += `
                                                                                                                    '${ one.title }': { \/\/${ one.required?'(必填) ':'' }${ one.note }；`
                for(var ii = 0, li = one.sub.length; ii < li; ii++){
                    var two = one.sub[ii]
                    templateA += `
                                                                                                                        '${ two.title }': '', \/\/${ two.note }；`

                }
                templateA += `
                                                                                                                    },`
            } else if( one.type == '对象数组' ){
                templateA += `
                                                                                                                    '${ one.title }': [ { \/\/${ one.required?'(必填) ':'' }${ one.note }；`
                for(var ii = 0, li = one.sub.length; ii < li; ii++){
                    var two = one.sub[ii]
                    templateA += `
                                                                                                                        '${ two.title }': '', \/\/${ two.note }；`

                }
                templateA += `
                                                                                                                    } , ...],`
            }
        }
        templateA += `
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                        var API = {
                                                                                                            'title': '${ json.api.title } (读取列表) '
                                                                                                            'url':'${ json.api.url }List', 
                                                                                                            'method': 'GET',
                                                                                                            'request': {
                                                                                                                'header': {},
                                                                                                                'params': {
                                                                                                                    'pageIndex': 1, \/\/ 当前页
                                                                                                                    'pageSize': 20, \/\/ 页容量
                                                                                                                    'orderName': '', \/\/ 排序列的name
                                                                                                                    'orderDir': '', \/\/ 排序规则('asc'或者'desc')
                                                                                                                }
                                                                                                            },
                                                                                                            'response': {
                                                                                                                'code': '200',
                                                                                                                'msg': '',
                                                                                                                'data': {
                                                                                                                    'dataList': [ {`
        for(var i = 0, l = json.requestColume.length; i < l; i++){
            var one = json.requestColume[i]
            if( one.type == '文本' ){
                templateA += `
                                                                                                                        '${ one.title }': '', \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数字' ){
                templateA += `
                                                                                                                        '${ one.title }': 1, \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数组' ){
                templateA += `
                                                                                                                        '${ one.title }': ['aaa', 'bbb', 'ccc'], \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '对象' ){
                templateA += `
                                                                                                                        '${ one.title }': { \/\/${ one.required?'(必填) ':'' }${ one.note }；`
                for(var ii = 0, li = one.sub.length; ii < li; ii++){
                    var two = one.sub[ii]
                    templateA += `
                                                                                                                            '${ two.title }': '', \/\/${ two.note }；`

                }
                templateA += `
                                                                                                                        },`
            } else if( one.type == '对象数组' ){
                templateA += `
                                                                                                                        '${ one.title }': [ { \/\/${ one.required?'(必填) ':'' }${ one.note }；`
                for(var ii = 0, li = one.sub.length; ii < li; ii++){
                    var two = one.sub[ii]
                    templateA += `
                                                                                                                            '${ two.title }': '', \/\/${ two.note }；`

                }
                templateA += `
                                                                                                                        } , ...],`
            }
        }
        templateA += `
                                                                                                                    } , ...],
                                                                                                                    'sumData': {`
        for(var i = 0, l = json.requestColume.length; i < l; i++){
            var one = json.requestColume[i]
            if( one.type == '文本' ){
                templateA += `
                                                                                                                        '${ one.title }Sum': '', \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数字' ){
                templateA += `
                                                                                                                        '${ one.title }Sum': 1, \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '数组' ){
                templateA += `
                                                                                                                        '${ one.title }Sum': ['aaa', 'bbb', 'ccc'], \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '对象' ){
                templateA += `
                                                                                                                        '${ one.title }Sum': '' \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            } else if( one.type == '对象数组' ){
                templateA += `
                                                                                                                        '${ one.title }Sum': '' \/\/${ one.required?'(必填) ':'' }${ one.note }；`
            }
        }
        templateA += `
                                                                                                                    },
                                                                                                                    'rowCount': 100, //总条数
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                        var API = {
                                                                                                            'title': '${ json.api.title } (下拉框) '
                                                                                                            'url':'${ json.api.url }Drop', 
                                                                                                            'method': 'GET',
                                                                                                            'request': {
                                                                                                                'header': {},
                                                                                                                'params': {
                                                                                                                }
                                                                                                            },
                                                                                                            'response': {
                                                                                                                'code': '200',
                                                                                                                'msg': '',
                                                                                                                'data': [
                                                                                                                    {'id': 1, 'name': ''},
                                                                                                                    ...
                                                                                                                ]
                                                                                                            }
                                                                                                        }`
        $('#templateA').html( templateA.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n[ ]{96}/g, '\n') )
    })
    $scope.printFromObj = (function() {
        var str = JSON.stringify($scope.fromObj)
        console.log( str )
        var storage = window.localStorage
        storage.setItem("makeApi14Code", str)
    })
    $scope.getFromObj = (function() {
        if( window.hahaha ){
            $scope.fromObj = json = window.hahaha
        } else {
            var storage = window.localStorage
            $scope.fromObj = json = eval( '('+storage.getItem("makeApi14Code")+')' )
        }
    })
}